package com.security.controller;

import com.security.common.code.ValidateCodeProcessorHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.configurationprocessor.json.JSONException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: TongRui乀
 * @Date: 2020/3/21 8:49
 * @description：
 */
@RestController
@RequestMapping("user")
public class UserController {


    @GetMapping("info")
    public Map<String,String> info() throws JSONException {

        HashMap<String, String> map = new HashMap<>();

        map.put("username","jack");
        map.put("mobile", "11111111111");

        return map;
    }

    @Autowired
    private ValidateCodeProcessorHolder validateCodeProcessorHolder;

    @GetMapping("code/{type}")
    public void imageCode(@PathVariable String type, HttpServletRequest request, HttpServletResponse response) throws IOException {

        this.validateCodeProcessorHolder.findValidateCodeProcessor(type).create(new ServletWebRequest(request, response));

    }

    @GetMapping("test")
    public String test(){
        return "success";
    }


}
